package controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.User2;
import service.UserLoginService;

//import javax.servlet.http.HttpServletRequest;
//import java.io.PrintWriter;
import java.util.List;

@Controller
public class AdminController {

    @RequestMapping("/searchuserlist2")
    @ResponseBody
    public JSONObject searchUserList(@RequestParam("currentPage") int currentPage,
                                     @RequestParam("pageSize") int pageSize) {
        UserLoginService userLoginService = new UserLoginService();
        List<User2> user2s = userLoginService.searchUserList();
        JSONObject jsonResponse = new JSONObject();

        int startIndex = (currentPage - 1) * pageSize;
        int endIndex = Math.min(startIndex + pageSize, user2s.size());
        List<User2> currentPageUsers = user2s.subList(startIndex, endIndex);
        System.out.println("SpringMVC执行中");
        jsonResponse.put("userList", currentPageUsers);
        jsonResponse.put("size", user2s.size());
        return jsonResponse;
    }
}
